package com.kaiyidiannao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.kaiyidiannao.data.DataCenter;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.SinaPoi;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 大志 on 14-4-4.
 * 天天惠Adaper
 */
public class SInaPoiTestAdapter extends BaseAdapter {
    private ImageLoader imageLoader;
    private Context context;
    private LayoutInflater layoutInflater;
    private List<SinaPoi> list = new ArrayList<SinaPoi>();

    public SInaPoiTestAdapter(Context context, List<SinaPoi> list) {
        this.context  = context;
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(context));
        this.list = list;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView thumeImageView = null;//缩略图
        TextView titleTextView = null;//标题
        TextView priceTextView = null;//价格
        TextView salesTextView = null;//销售量
        ImageView favoritesImageView = null;//收藏

        final SinaPoi bean = list.get(position);
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.daydaycoupon_list_item, null);
        }
        thumeImageView = (ImageView) convertView.findViewById(R.id.daydaycoupon_thumb);
        titleTextView = (TextView) convertView.findViewById(R.id.daydaycoupon_title);
        priceTextView = (TextView) convertView.findViewById(R.id.daydaycoupon_price);
        salesTextView = (TextView) convertView.findViewById(R.id.daydaycoupon_sales);
        favoritesImageView = (ImageView) convertView.findViewById(R.id.daydaycoupon_favorites);
        salesTextView.setText(bean.getAddress());
        titleTextView.setText(bean.getName());
        priceTextView.setText(bean.getType());
        favoritesImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(DataCenter.context, bean.getAddress() + "已经被成功收藏", Toast.LENGTH_SHORT).show();
            }
        });
        return convertView;
    }
}
